<div class="row">
	<div class="col-lg-6">
		<div class="alert alert-danger">
			<h3>注意：</h3>
			<p>账务人员收到充值款项后再给客户充值！</p>
			<p>充值后不可修改，请认真核对数据！</p>
		</div>

		<div class="input-group">
			<div class="input-group-addon">充值金额</div>
			<input type="number" class="form-control" id="money" name="money" placeholder="请输入整数">
			<div class="input-group-addon">等于</div>
			<input type="number" class="form-control" readonly="readonly" id="pv" name="pv">
			<div class="input-group-addon">流量</div>
			<div class="input-group-addon">注：1元人民币={$config.pv_price}流量</div>
			<input type="text" class="form-control" id="note" name="note" placeholder="请输入备注信息">
			<span class="input-group-btn">
                <button id="submit" class="btn btn-primary" type="button">充值</button>
            </span>
		</div>
	</div>
</div>

<hr />

<div class="row">
	<div class="col-sm-6">
		<div class="alert alert-success">
			<h4>数据统计</h4>
			<hr>
			<ul>
				<li>充值总额(￥)：<code>{$customer.totalMoney}</code>
				</li>
				<li>初始流量额度：<code>{$customer.pv_default}</code>
				</li>
				<li>充值流量额度：<code>{$customer.pv_count}</code>
				</li>
				<li>当前总流量：<code>{$customer.pv}</code>
				</li>
				<li>剩余流量：<code>{$customer.pv_rest}</code>
				</li>
				<li>平均日流量：<code>{$customer.pv_avg}</code>
				</li>
				<li>近一周平均日流量：<code>{$customer.pv_week_avg}</code>
				</li>
				<li>预计还可使用天数：<code>{$customer.day_rest}</code>（注：根据近一周平均流量预估，可能会和实际有出入）</li>
			</ul>
		</div>
		<div class="alert alert-success">
			<p>平台初始赠送 <code>{$config.free_pv}</code> 流量，后期续费标准为 <code>{$config.pv_price}流量/1元人民币</code> 。</p>
			<p>为了不影响您的使用，请您提前充值。联系电话：{$config.tel}。联系QQ：{$config.qq}</p>
		</div>
	</div>
	<div class="col-sm-6">
		<div class="alert alert-info">
			<h4>最近7日流量</h4>
			<hr>
			<table class="table table-condensed">
				<thead>
					<tr>
						<th>ID</th>
						<th>日期</th>
						<th>流量</th>
					</tr>
				</thead>
				<tbody>
					<volist name="reports" id="vo">
						<tr>
							<td>{$i}</td>
							<td>{$vo.date}</td>
							<td>{$vo.pv}</td>
						</tr>
					</volist>
				</tbody>
			</table>
		</div>
	</div>
</div>


<script type="text/javascript">
	var price = parseInt("{$config.pv_price}");
	var cid = "{$sid}";
	var money;
	var pv;
	$(function() {
		$("#money").bind('change', function() {
			money = parseInt($(this).val());
			if (isNaN(money) || money <= 0) {
				$(this).val("").focus();
				money = 0;
			}
			pv = money ? money * price : '';
			$("#pv").val(pv);
		});
		$("#submit").click(function() {
			var othis = $(this);
			if (money && pv) {
				$.ajax({
					type: "POST",
					url: "__CONTROLLER__/saveFinance",
					data: {
						cid: cid,
						money: money,
						pv: pv,
						note: $("#note").val()
					},
					beforeSend: function() {
						othis.attr("disabled", true);
					},
					success: function(data) {
						if (data.error == 0) {
							$("#money").val("");
							$("#note").val("");
							$("#pv").val("");
							$().alertMsg({
								type: 'success',
								msg: data.msg
							});
							location.reload();
						} else {
							$().alertMsg({
								type: 'danger',
								msg: data.msg
							});
						}
					},
					error: function() {
						$().alertMsg({
							type: 'danger',
							msg: '网络错误，请重试！'
						});
					},
					complete: function() {
						othis.removeAttr('disabled');
					}
				});
			} else {
				$("#money").focus();
				$().alertMsg({
					type: 'danger',
					msg: '请输入充值金额！'
				});
			}
		});
	});
</script>